//
// Created by hsj on 2022/3/8.
//
#include "t_string.h"

namespace t_string_test{
    //测试
    void test(){
      string one("Lottery Winner.");
      cout<<one<<endl;

      string two(20,'$');
      cout<<two<<endl;

      //复制构造函数
      string three(one);
      cout<<three<<endl;

      //重载 +=
      one+=" HSJ.";
      cout<<one<<endl;

      //重载赋值
      two = "over load =.";
      cout<<two<<endl;

      //默认构造函数
      string four;
      //重载 + =
      four  = two + three;
      cout<<four<<endl;

      //alls代表第一个元素的地址
      char alls[] = "All's well that ends well.";
      string five(alls,20);
      cout<<five<<endl;

      //左包含，右边不包含
      //地址
      string six(alls+1,alls+10);
      cout<<six<<endl;
      string seven(&five[1],&five[10]);
      cout<<seven<<endl;

      //截取
      string eight(four,7,16);
      cout<<eight<<endl;

      //C++11，列表初始化方式
      string nine{'H','S','J','I','S','M','A','R','T'};
      cout<<nine<<endl;


      //比较字符串
      //字面量比较（类似java的equals）
      string snake1("snake");
      string snake2("snake");
      char snake3[20]{"anaconda"};

      if (snake1 == snake2){
            cout<<"snake1 == snake2"<<endl;
      }else{
            cout<<"snake1 != snake2"<<endl;
      }
      if (snake1 == snake3){
            cout<<"snake1 == snake3"<<endl;
      }else{
            cout<<"snake1 != snake3"<<endl;
      }


      //内存空间
      string m1 = "m1";
      string m2 = "m2";
      string m3 = "here is m3 in memery space is little big.";
      //size length表示字符串的实际长度
      cout<<"size(m1 m2 m3) :"<<m1.size()<<" "<<m2.size()<<" "<<m3.size()<<endl;
      //capacity:表示内存块的大小
      cout<<"capacity(m1 m2 m3) :"<<m1.capacity()<<" "<<m2.capacity()<<" "<<m3.capacity()<<endl;
      //reserve:表示能够请求内存块的最小长度
      m1.reserve(50);
      cout<<"capacity(m1) :"<<m1.capacity()<<endl;

    }
}